<?php
include("include/config.inc.php");
$iserror = 0;
if(isset($_POST['fName']) && strlen($_POST['fName']) > 0 || isset($_POST['password']) && strlen($_POST['password']) > 0)
{
  $checkLogin = "SELECT userId,fName,password,userType
                   FROM user
                  WHERE fName = '".$_POST['fName']."'
                    AND password = '".$_POST['password']."'
                    AND userType = 'admin'";
  $checkLoginresult = mysql_query($checkLogin);
  if($userLoginRow = mysql_fetch_array($checkLoginresult))
  {
    $_SESSION['s_activIdsAdmin'] = $userLoginRow['userId'];
    if(!$_SESSION['s_urlRedirectDir'])
    {
      header("Location:./index.php");
    }
    else
    {
      header("Location:".$_SESSION['s_urlRedirectDir']);
    }
  }
  else
  {
  	$checkLogin2 = "SELECT userId,fName,password,userType
	                    FROM user
	                   WHERE fName = '".$_POST['fName']."'
	                     AND password = '".$_POST['password']."'
	                     AND userType = 'admin2'";
	  $checkLogin2result = mysql_query($checkLogin2);
	  if($userLogin2Row = mysql_fetch_array($checkLogin2result))
	  {
	    $_SESSION['s_activIdsAdmin2'] = $userLogin2Row['userId'];
	    if(!$_SESSION['s_urlRedirectDir2'])
	    {
	      header("Location:./uploadPic.php");
	    }
	    else
	    {
	      header("Location:".$_SESSION['s_urlRedirectDir2']);
	    }
	  }
	  else
	  {
	    $iserror = 1;
	  }
  }
}
include("bottom.php");
$smarty->assign("iserror",$iserror);
$smarty->display("checkLogin.tpl");
?>